//
//  NavigatObject.m
//  Light
//
//  Created by 陈剑伟 on 15/12/7.
//  Copyright © 2015年 陈剑伟. All rights reserved.
//

#import "NavigatObject.h"

@implementation NavigatObject
-(void)StringToNative:(NSString *)string
{//http://dt_jscall:method=set_coloe&action=SET_COLOE&r=222&g=32&b=81
    NSString *tem;
   NSRange obcrang=[string rangeOfString:@"objc:"];
    if (obcrang.location==NSNotFound) {
        tem=string;
    }
    else
    {
        tem=[string substringFromIndex:5];
    }
    NSString *substring=[tem substringWithRange:NSMakeRange(17, tem.length-17)];
    NSArray *ary=[substring componentsSeparatedByString:@"&"];
    self.Methodstring=[ary[0]componentsSeparatedByString:@"="][1];
    if ([[ary[1]componentsSeparatedByString:@"="][0]isEqualToString:@"action"]) {
        self.Actionstring=[ary[1]componentsSeparatedByString:@"="][1];
        NSMutableArray *tem=[NSMutableArray array];
        NSMutableDictionary *temdic=[NSMutableDictionary dictionary];
        for (int i=2; i<ary.count; i++) {
            NSArray *temary=[ary[i] componentsSeparatedByString:@"="];
            [temdic setObject:temary[1] forKey:temary[0]];
            NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:temary[1],temary[0], nil];
            [tem addObject:dic];
        }
        self.Paramsdic=temdic;
        self.Params=tem;
    }else
    {
        NSMutableArray *tem=[NSMutableArray array];
        NSMutableDictionary *temdic=[NSMutableDictionary dictionary];
        for (int i=1; i<ary.count; i++) {
            NSArray *temary=[ary[i] componentsSeparatedByString:@"="];
            [temdic setObject:temary[1] forKey:temary[0]];
            NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:temary[1],temary[0], nil];
            [tem addObject:dic];
        }
        
        self.Paramsdic=temdic;
        self.Params=tem;
    }
    
}

- (void)stringToHtmlString:(NSString *)string
{
    NSMutableDictionary *temdic = [[NSMutableDictionary alloc]init];
    NSArray *ary = [string componentsSeparatedByString:@"&"];
    if (ary.count > 1) {
        for (int i = 1; i < ary.count; i++) {
            NSArray *temary=[ary[i] componentsSeparatedByString:@"="];
            
            [temdic setObject:[temary[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] forKey:temary[0]];
        }
        if (temdic[@"action"] != nil) {
            self.Paramsdic = temdic;
        }
    }
}
@end
